home *** CD-ROM | disk | FTP | other *** search
/ Programming a Multiplayer FPS in DirectX / Programming a Multiplayer FPS in DirectX (Companion CD).iso / DirectX / dxsdk_oct2004.exe / dxsdk.exe / Samples / C++ / Direct3D / MultiAnimation / MultiAnimation.fx < prev    next >
Encoding:
Text File  |  2004-09-27  |  4.1 KB  |  152 lines

  1. //--------------------------------------------------------------------------------------
  2. // File: ShadowVolume.fx
  3. //
  4. // The effect file for the MultiAnimation sample.  
  5. // 
  6. // Copyright (c) Microsoft Corporation. All rights reserved.
  7. //--------------------------------------------------------------------------------------
  8.  
  9.  
  10. #include "skin.vsh"
  11.  
  12.  
  13. float4 lhtDir       = { 0.0f, 0.0f, -1.0f, 1.0f };  // Light Direction
  14. float4 lightDiffuse = { 0.6f, 0.6f, 0.6f, 1.0f };   // Light Diffuse
  15. float4 MaterialAmbient : MATERIALAMBIENT = { 0.1f, 0.1f, 0.1f, 1.0f };
  16. float4 MaterialDiffuse : MATERIALDIFFUSE = { 0.8f, 0.8f, 0.8f, 1.0f };
  17.  
  18. float4x4 g_mWorld : WORLD;
  19. float4x4 g_mViewProj : VIEWPROJECTION;
  20.  
  21. texture g_txScene;
  22.  
  23.  
  24. //--------------------------------------------------------------------------------------
  25. // Texture samplers
  26. //--------------------------------------------------------------------------------------
  27. sampler g_samScene =
  28. sampler_state
  29. {
  30.     Texture = <g_txScene>;
  31.     MinFilter = Linear;
  32.     MagFilter = Linear;
  33.     MipFilter = Point;
  34. };
  35.  
  36.  
  37. //--------------------------------------------------------------------------------------
  38. struct VS_INPUT
  39. {
  40.     float4  Pos             : POSITION;
  41.     float3  BlendWeights    : BLENDWEIGHT;
  42.     float4  BlendIndices    : BLENDINDICES;
  43.     float3  Normal          : NORMAL;
  44.     float3  Tex0            : TEXCOORD0;
  45. };
  46.  
  47. struct VS_OUTPUT
  48. {
  49.     float4  Pos     : POSITION;
  50.     float4  Diffuse : COLOR0;
  51.     float2  Tex0    : TEXCOORD0;
  52. };
  53.  
  54.  
  55. VS_OUTPUT VertScene( float4 Pos : POSITION,
  56.                      float3 Normal : NORMAL,
  57.                      float2 Tex0 : TEXCOORD0 )
  58. {
  59.     VS_OUTPUT o;
  60.     
  61.     o.Pos = mul( Pos, g_mWorld );
  62.     o.Pos = mul( o.Pos, g_mViewProj );
  63.     o.Tex0 = Tex0;
  64.     float3 N = normalize( mul( Normal, (float3x3)g_mWorld ) );
  65.  
  66.     // Always fully lit the floor
  67.     o.Diffuse = 1.0f;
  68.     
  69.     return o;
  70. }
  71.  
  72. float4 PixScene( float4 Diffuse : COLOR0,
  73.                  float2 Tex0 : TEXCOORD0 ) : COLOR0
  74. {
  75.     return tex2D( g_samScene, Tex0 ) * Diffuse;
  76. }
  77.  
  78.  
  79. VS_OUTPUT VertSkinning( VS_INPUT i, uniform int iNumBones )
  80. {
  81.     VS_OUTPUT   o;
  82.     float3      Pos = 0.0f;
  83.     float3      Normal = 0.0f;
  84.     float       LastWeight = 0.0f;
  85.     
  86.     // skin VB inputs
  87.     VS_SKIN_INPUT vsi = { i.Pos, i.BlendWeights, i.BlendIndices, i.Normal };
  88.     VS_SKIN_OUTPUT vso = VS_Skin( vsi, iNumBones );
  89.  
  90.     // transform position from world space into view and then projection space
  91.     o.Pos = mul( float4( vso.vPos.xyz, 1.0f ), g_mViewProj );
  92.  
  93.     // normalize normals
  94.     Normal = normalize( vso.vNor );
  95.  
  96.     // Shade (Ambient + etc.)
  97.     o.Diffuse = float4( MaterialAmbient.xyz + saturate( dot( Normal, lhtDir.xyz ) ) * MaterialDiffuse.xyz, 1.0 );
  98.  
  99.     // copy the input texture coordinate through
  100.     o.Tex0  = i.Tex0.xy;
  101.  
  102.     return o;
  103. }
  104.  
  105.  
  106. int CurNumBones = 2;
  107.  
  108. VertexShader vsArray20[ 4 ] = { compile vs_2_0 VertSkinning( 1 ),
  109.                                 compile vs_2_0 VertSkinning( 2 ),
  110.                                 compile vs_2_0 VertSkinning( 3 ),
  111.                                 compile vs_2_0 VertSkinning( 4 ) };
  112.  
  113. VertexShader vsArray11[ 4 ] = { compile vs_1_1 VertSkinning( 1 ),
  114.                                 compile vs_1_1 VertSkinning( 2 ),
  115.                                 compile vs_1_1 VertSkinning( 3 ),
  116.                                 compile vs_1_1 VertSkinning( 4 ) };
  117.  
  118.  
  119. //--------------------------------------------------------------------------------------
  120. // Techniques
  121. //--------------------------------------------------------------------------------------
  122.  
  123.  
  124. technique RenderScene
  125. {
  126.     pass p0
  127.     {
  128.         VertexShader = compile vs_1_1 VertScene();
  129.         PixelShader = compile ps_1_1 PixScene();
  130.     }
  131. }
  132.  
  133.  
  134. technique Skinning20
  135. {
  136.     pass p0
  137.     {
  138.         VertexShader = ( vsArray20[ CurNumBones ] );
  139.         PixelShader = compile ps_1_1 PixScene();
  140.     }
  141. }
  142.  
  143.  
  144. technique Skinning11
  145. {
  146.     pass p0
  147.     {
  148.         VertexShader = ( vsArray11[ CurNumBones ] );
  149.         PixelShader = compile ps_1_1 PixScene();
  150.     }
  151. }
  152.